package com.zhump.springcloud.zookeeper.server.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.io.Serializable;
import java.util.List;

/**
 * zookeeper测试类
 */
@RestController
@RequestMapping("/zookeeper")
public class ZookeeperController {


    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private RestTemplate restTemplate;


    @RequestMapping("/consums")
    public ModelMap test() {
        List<ServiceInstance> list = discoveryClient.getInstances("spring-cloud-zookeeper-server");
        ModelMap modelMap = new ModelMap();
        modelMap.put("reslut","not get service");
        if (list == null || list.size() <= 0){

            return modelMap;
        }
        modelMap.put("reslut",list);
        return modelMap;
    }

    @RequestMapping("/getServer")
    public String getServer(){
        return restTemplate.getForObject("http://spring-cloud-zookeeper-server/zookeeper/server",String.class);
    }
}



